package com.spddr.pmos;

import java.util.List;

import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import cn.seqdata.cxf.SpringConfigurationFactory;
import cn.seqdata.cxf.provider.GsonProvider;
import cn.seqdata.cxf.provider.JacksonProvider;

@Configuration
public class RptConfiguration extends SpringConfigurationFactory {

	@Override
	protected String getAddress() {
		return "/rpt";
	}

	@Override
	protected List<Object> getJaxrsProviders() {
		List<Object> providers = super.getJaxrsProviders();

		for (Object provider : providers) {
			if (provider.getClass().isAssignableFrom(JacksonProvider.class)) {
				providers.remove(provider);
			}
		}
		providers.add(new GsonProvider());

		return providers;
	}

	@Override
	protected void setJaxrsResources(JAXRSServerFactoryBean sf) {
		sf.setServiceClass(com.spddr.pmos.rpt.impl.RtpGeneralImpl.class);
		sf.setServiceClass(com.spddr.pmos.rpt.impl.RptRainStationImpl.class);
		sf.setServiceClass(com.spddr.pmos.rpt.impl.RptHydrologyStationImpl.class);
		sf.setServiceClass(com.spddr.pmos.rpt.impl.RptReservoirSupplyLevelImpl.class);
		sf.setServiceClass(com.spddr.pmos.rpt.impl.RptReservoirFlowImpl.class);
		sf.setServiceClass(com.spddr.pmos.rpt.impl.RptReservoirForecastImpl.class);

		sf.setServiceClass(com.spddr.pmos.rpt.impl.RptPlantGeneratingCapacityImpl.class);
		sf.setServiceClass(com.spddr.pmos.rpt.impl.RptPlantOnGrIdEnergyImpl.class);
		sf.setServiceClass(com.spddr.pmos.rpt.impl.RptPlantPlanImpl.class);
		
		sf.setServiceClass(com.spddr.pmos.rpt.impl.RptUnitPowerImpl.class);
	}

	@Bean
	public Server rptServer() {
		return super.createJaxRsServer();
	}
}
